package models

import (
	"errors"
	"gorm.io/gorm"
)

type NoticeContextModel struct {
	ID            int    `gorm:"primaryKey" xorm:"id"`
	NoticeContext string `xorm:"notice_context" gorm:"column:notice_context"`
	NoticeTitle   string `gorm:"column:notice_title" xorm:"notice_title"`
	CTime         int    `gorm:"column:ctime" xorm:"ctime"`
}

func (this *NoticeContextModel) TableName() string {
	return "kc_notice_context"
}
func (this *NoticeContextModel) Table() string {
	return this.TableName()
}
func (this *NoticeContextModel) BeforeCreate(tx *gorm.DB) (err error) {
	if this.NoticeContext == "sin" {
		this.NoticeContext += "version"
	}
	if this.NoticeContext == "test" {
		return errors.New("Invalid notice_context")
	}
	return
}
